package com.cl.master.service.impl;

import com.cl.master.domain.SewageStandard;
import com.cl.master.mapper.SewageStandardMapper;
import com.cl.master.service.SewageStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Author xc
 * @Date 2023/4/26 15:39
 * @Version 1.0
 */
@Service
public class SewageStandardServiceImpl implements SewageStandardService {

    @Autowired
    SewageStandardMapper sewageStandardMapper;

    @Override
    public Collection<SewageStandard> getAllInfo(int startPage) {

        /*try {
            //换成你的文件名
            BufferedReader reader = new BufferedReader(
                    new FileReader("C:\\Users\\10160\\Desktop\\大三上作业\\服务外包\\数据\\data.csv"));
            //第一行信息，为标题信息，不用,如果需要，注释掉
            //reader.readLine();
            String line = null;
            while ((line = reader.readLine()) != null) {
                //CSV格式文件为逗号分隔符文件，这里根据逗号切分
                String item[] = line.split(",");
                String companyCode = item[0];
                String outletCode = item[1];
                String contaminantCode = item[2];
                *//**
         * SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
         * String time = "2019-09-19";
         * Date date = ft.parse(time)
         *//*
                SimpleDateFormat ft = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
                String recordTime = item[3];
                Date date = ft.parse(recordTime);

                Double pollutantConcentration = Double.valueOf(item[4]);
                Double pollutantDischarge = Double.valueOf(item[5]);
                *//*企业排污信息实例*//*
                SewageStandard sewageStandard = new SewageStandard(
                        companyCode,
                        outletCode,
                        contaminantCode,
                        date,
                        pollutantConcentration,
                        pollutantDischarge);
                sewageStandardMapper.addAllInfo(sewageStandard);
                //这就是你要的数据了
                //String last = item[0];
                //int value = Integer.parseInt(last);//如果是数值，可以转化为数值
            }
        } catch (Exception e) {
            e.printStackTrace();
        }*/

        Collection<SewageStandard> allInfo = sewageStandardMapper.getAllInfo(startPage);
        System.out.println("所有企业的排污信息已全部查询完毕");
        return allInfo;
    }

    @Override
    public Collection<SewageStandard> getInfoByCode(String code) {
        Collection<SewageStandard> infoByCode = sewageStandardMapper.getInfoByCode(code);
        System.out.println("企业编号为："+code+"排污信息已全部查询完毕");
        return infoByCode;
    }

    @Override
    public void addAllInfo(SewageStandard sewageStandard) {
        sewageStandardMapper.addAllInfo(sewageStandard);
    }

    @Override
    public List<Map<String, Object>> getEnterpriseData() {
        List<Map<String,Object>> data = sewageStandardMapper.getEnterpriseData();
        return data;
    }



}
